package File;

import java.io.*;
import java.util.Scanner;

public class Demo19 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        System.out.println("请输入源文件路径：");
        String srcPath=in.next();
        System.out.println("请输入目标文件路径：");
        String destPath=in.next();
        File srcFile=new File(srcPath);
        if(!srcFile.isFile()){
            System.out.println("源文件路径所指不是文件或文件不存在");
            return;
        }
File destFile=new File(destPath);
        if(!destFile.getParentFile().isDirectory()){
            System.out.println("目标文件所在目录不存在");
            return;
        }

        try(InputStream inputStream=new FileInputStream(srcFile);
            OutputStream outputStream=new FileOutputStream(destFile)) {
while(true){
    byte[]data=new byte[1024];
    int n=inputStream.read(data);
    if(n==-1)break;
    outputStream.write(data,0,n);
}
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
